<!DOCTYPE html>

































































<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="shortcut icon" type="image/x-icon" href="../../favicon.ico" />
<title>Application Fundamentals | Android Developers</title>
<link href="../../assets/android-developer-docs-devguide.css" rel="stylesheet" type="text/css" />
<script src="../../assets/search_autocomplete.js" type="text/javascript"></script>
<script src="../../assets/jquery-resizable.min.js" type="text/javascript"></script>
<script src="../../assets/android-developer-docs.js" type="text/javascript"></script>
<script src="../../assets/prettify.js" type="text/javascript"></script>
<script type="text/javascript">
  setToRoot("../../");
</script>
<noscript>
  <style type="text/css">
    html,body{overflow:auto;}
    #body-content{position:relative; top:0;}
    #doc-content{overflow:visible;border-left:3px solid #666;}
    #side-nav{padding:0;}
    #side-nav .toggle-list ul {display:block;}
    #resize-packages-nav{border-bottom:3px solid #666;}
  </style>
</noscript>
</head>
<body class="gc-documentation">

  <div id="header">
      <div id="headerLeft">
          <a href="../../index.html" tabindex="-1"><img
              src="../../assets/images/bg_logo.png" alt="Android Developers" /></a>
          <ul id="header-tabs" class="guide">
    
	<li id="home-link"><a href="../../offline.html">
	
		<span class="en">Home</span>
		<span style="display:none" class="de">Startseite</span>
		<span style="display:none" class="es"></span>
		<span style="display:none" class="fr"></span>
		<span style="display:none" class="it"></span>
		<span style="display:none" class="ja">ホーム</span>
		<span style="display:none" class="zh-CN">主页</span>
		<span style="display:none" class="zh-TW">首頁</span>
	
	</a></li>
	<li id="sdk-link"><a href="../../sdk/index.html">
		<span class="en">SDK</span>
	</a></li>
	<li id="guide-link"><a href="../../guide/index.html" onClick="return loadLast('guide')">
	
		<span class="en">Dev Guide</span>
		<span style="display:none" class="de">Handbuch</span>
		<span style="display:none" class="es">Guía</span>
		<span style="display:none" class="fr">Guide</span>
		<span style="display:none" class="it">Guida</span>
		<span style="display:none" class="ja">開発ガイド</span>
		<span style="display:none" class="zh-CN">开发人员指南</span>
		<span style="display:none" class="zh-TW">開發指南</span>
	
	</a></li>
	<li id="reference-link"><a href="../../reference/packages.html" onClick="return loadLast('reference')">
	
		<span class="en">Reference</span>
		<span style="display:none" class="de">Referenz</span>
		<span style="display:none" class="es">Referencia</span>
		<span style="display:none" class="fr">Référence</span>
		<span style="display:none" class="it">Riferimento</span>
		<span style="display:none" class="ja">リファレンス</span>
		<span style="display:none" class="zh-CN">参考</span>
		<span style="display:none" class="zh-TW">參考資料</span>
	
	</a></li>
	<li id="resources-link"><a href="../../resources/index.html" onClick="return loadLast('resources')">
	
		<span class="en">Resources</span>
		<span style="display:none" class="de"></span>
		<span style="display:none" class="es"></span>
		<span style="display:none" class="fr"></span>
		<span style="display:none" class="it"></span>
    		<span style="display:none" class="ja"></span>
		<span style="display:none" class="zh-CN"></span>
		<span style="display:none" class="zh-TW"></span>
	
	</a></li>
	<li id="videos-link"><a href="../../videos/index.html" onClick="return loadLast('videos')">
	
		<span class="en">Videos</span>
		<span style="display:none" class="de"></span>
		<span style="display:none" class="es"></span>
		<span style="display:none" class="fr"></span>
		<span style="display:none" class="it"></span>
		<span style="display:none" class="ja">ビデオ</span>
		<span style="display:none" class="zh-CN"></span>
		<span style="display:none" class="zh-TW"></span>
	
	</a></li>
	<li><a href="http://android-developers.blogspot.com" onClick="return requestAppendHL(this.href)">
	
		<span class="en">Blog</span>
		<span style="display:none" class="de"></span>
		<span style="display:none" class="es"></span>
		<span style="display:none" class="fr"></span>
		<span style="display:none" class="it"></span>
		<span style="display:none" class="ja">ブログ</span>
		<span style="display:none" class="zh-CN">博客</span>
		<span style="display:none" class="zh-TW">網誌</span>
	
	</a></li>


     
</ul>
     
      </div>
      <div id="headerRight">
          <div id="headerLinks">
          
          <a href="http://www.android.com">Android.com</a>
          </div>
  <div id="search" >
      <div id="searchForm">
          <form accept-charset="utf-8" class="gsc-search-box" 
                onsubmit="return submit_search()">
            <table class="gsc-search-box" cellpadding="0" cellspacing="0"><tbody>
                <tr>
                  <td class="gsc-input">
                    <input id="search_autocomplete" class="gsc-input" type="text" size="33" autocomplete="off"
                      title="search developer docs" name="q"
                      value="search developer docs"
                      onFocus="search_focus_changed(this, true)"
                      onBlur="search_focus_changed(this, false)"
                      onkeydown="return search_changed(event, true, '../../')"
                      onkeyup="return search_changed(event, false, '../../')" />
                  <div id="search_filtered_div" class="no-display">
                      <table id="search_filtered" cellspacing=0>
                      </table>
                  </div>
                  </td>
                  <td class="gsc-search-button">
                    <input type="submit" value="Search" title="search" id="search-button" class="gsc-search-button" />
                  </td>
                  <td class="gsc-clear-button">
                    <div title="clear results" class="gsc-clear-button">&nbsp;</div>
                  </td>
                </tr></tbody>
              </table>
          </form>
      </div><!-- searchForm -->
  </div><!-- search -->
      </div><!-- headerRight -->
      <script type="text/javascript">
        <!--  
        changeTabLang(getLangPref());
        //-->
      </script>
  </div><!-- header -->

  <div class="g-section g-tpl-240" id="body-content">
    <div class="g-unit g-first" id="side-nav">
      <div id="devdoc-nav">
<ul>

  <li>
    <h2><span class="en">Android Basics</span>
        <span class="de" style="display:none">Einführung in Android</span>
        <span class="es" style="display:none">Información básica sobre Android</span>
        <span class="fr" style="display:none">Présentation d'Android</span>
        <span class="it" style="display:none">Nozioni di base su Android</span>
        <span class="ja" style="display:none">Android の基本</span>
        <span class="zh-CN" style="display:none">Android 基础知识</span>
        <span class="zh-TW" style="display:none">Android 簡介</span>
    </h2>
    <ul>
      <li><a href="../../guide/basics/what-is-android.html">
        <span class="en">What Is Android?</span>
        <span class="de" style="display:none">Was ist Android?</span>
        <span class="es" style="display:none">¿Qué es Android?</span>
        <span class="fr" style="display:none">Qu'est-ce qu'Android&nbsp;?</span>
        <span class="it" style="display:none">Che cos'è Android?</span>
        <span class="ja" style="display:none">Android とは</span>
        <span class="zh-CN" style="display:none">Android 是什么？</span>
        <span class="zh-TW" style="display:none">什麼是 Android？</span>
          </a></li>
      <li><a href="../../guide/topics/fundamentals.html">
        <span class="en">Application Fundamentals</span>
        <span class="de" style="display:none">Anwendungsgrundlagen</span>
        <span class="es" style="display:none">Fundamentos de las aplicaciones</span>
        <span class="fr" style="display:none">Principes de base des applications</span>
        <span class="it" style="display:none">Concetti fondamentali sulle applicazioni</span>
        <span class="ja" style="display:none">開発の基礎</span>
        <span class="zh-CN" style="display:none">应用程序基础</span>
        <span class="zh-TW" style="display:none">應用程式基本原理</span>
      </a></li>

  <!--  <li><a style="color:gray;">The Android SDK</a></li> -->
  <!--  <li><a style="color:gray;">Walkthrough for Developers</a></li> -->
      <!-- quick overview of what it's like to develop on Android -->
    </ul>
  </li>

  <li>
    <h2>
      <span class="en">Framework Topics</span>
      <span class="de" style="display:none">Framework-Themen</span>
      <span class="es" style="display:none">Temas sobre el framework</span>
      <span class="fr" style="display:none">Thèmes relatifs au framework</span>
      <span class="it" style="display:none">Argomenti relativi al framework</span>
      <span class="ja" style="display:none">フレームワーク トピック</span>
      <span class="zh-CN" style="display:none">框架主题</span>
      <span class="zh-TW" style="display:none">架構主題</span>
    </h2>
    <ul>
      <li class="toggle-list">
        <div><a href="../../guide/topics/fundamentals/activities.html">
          <span class="en">Activities</span>
        </a></div>
        <ul>
          <li><a href="../../guide/topics/fundamentals/fragments.html">
            <span class="en">Fragments</span>
          </a></li>
          <li><a href="../../guide/topics/fundamentals/loaders.html">
            <span class="en">Loaders</span>
          </a></li>
          <li><a href="../../guide/topics/fundamentals/tasks-and-back-stack.html">
            <span class="en">Tasks and Back Stack</span></a></li>
        </ul>
      </li>
      <li class="toggle-list">
        <div><a href="../../guide/topics/fundamentals/services.html">
          <span class="en">Services</span>
        </a></div>
        <ul>
          <li><a href="../../guide/topics/fundamentals/bound-services.html">
            <span class="en">Bound Services</span>
          </a></li>
        </ul>
      </li>
      <li><a href="../../guide/topics/providers/content-providers.html">
            <span class="en">Content Providers</span>
          </a></li>
      <li><a href="../../guide/topics/intents/intents-filters.html">
            <span class="en">Intents and Intent Filters</span>
          </a></li>
      <li><a href="../../guide/topics/fundamentals/processes-and-threads.html">
            <span class="en">Processes and Threads</span>
          </a></li>
    </ul>


    <ul>
      <li class="toggle-list">
        <div><a href="../../guide/topics/ui/index.html">
            <span class="en">User Interface</span>
          </a></div>
        <ul>
          <li><a href="../../guide/topics/ui/declaring-layout.html">
               <span class="en">XML Layouts</span>
              </a></li>
          <li><a href="../../guide/topics/ui/ui-events.html">
                <span class="en">Input Events</span>
              </a></li>
          <li><a href="../../guide/topics/ui/menus.html">
               <span class="en">Menus</span>
              </a></li>
          <li><a href="../../guide/topics/ui/actionbar.html">
               <span class="en">Action Bar</span>
              </a></li>
          <li><a href="../../guide/topics/ui/dialogs.html">
                <span class="en">Dialogs</span>
              </a></li>
          <li class="toggle-list">
            <div><a href="../../guide/topics/ui/notifiers/index.html">
                <span class="en">Notifications</span>
            </a></div>
            <ul>
              <li><a href="../../guide/topics/ui/notifiers/toasts.html">
                <span class="en">Toast Notifications</span>
              </a></li>
              <li><a href="../../guide/topics/ui/notifiers/notifications.html">
                <span class="en">Status Bar Notifications</span>
              </a></li>
            </ul>
          </li>
          <li><a href="../../guide/topics/ui/drag-drop.html">
                <span class="en">Drag and Drop</span>
              </a></li>
          <li><a href="../../guide/topics/ui/themes.html">
                <span class="en">Styles and Themes</span>
              </a></li>
          <li><a href="../../guide/topics/ui/custom-components.html">
                <span class="en">Custom Components</span>
              </a></li>
          <li><a href="../../guide/topics/ui/binding.html">
                <span class="en">Binding to Data with AdapterView</span>
              </a></li>
          <li><a href="../../guide/topics/ui/layout-objects.html">
                <span class="en">Common Layout Objects</span>
              </a></li>
          <li><a href="../../guide/topics/ui/how-android-draws.html">
                <span class="en">How Android Draws Views</span>
              </a></li>
        </ul>
      </li><!-- end of User Interface -->

      <li class="toggle-list">
        <div><a href="../../guide/topics/resources/index.html">
               <span class="en">Application Resources</span>
             </a></div>
        <ul>
          <li><a href="../../guide/topics/resources/providing-resources.html">
                <span class="en">Providing Resources</span>
              </a></li>
          <li><a href="../../guide/topics/resources/accessing-resources.html">
                <span class="en">Accessing Resources</span>
              </a></li>
          <li><a href="../../guide/topics/resources/runtime-changes.html">
                <span class="en">Handling Runtime Changes</span>
              </a></li>
          <li><a href="../../guide/topics/resources/localization.html">
                <span class="en">Localization</span>
              </a></li>
          <li class="toggle-list">
            <div><a href="../../guide/topics/resources/available-resources.html">
              <span class="en">Resource Types</span>
            </a></div>
            <ul>
              <li><a href="../../guide/topics/resources/animation-resource.html">Animation</a></li>
              <li><a href="../../guide/topics/resources/color-list-resource.html">Color State List</a></li>
              <li><a href="../../guide/topics/resources/drawable-resource.html">Drawable</a></li>
              <li><a href="../../guide/topics/resources/layout-resource.html">Layout</a></li>
              <li><a href="../../guide/topics/resources/menu-resource.html">Menu</a></li>
              <li><a href="../../guide/topics/resources/string-resource.html">String</a></li>
              <li><a href="../../guide/topics/resources/style-resource.html">Style</a></li>
              <li><a href="../../guide/topics/resources/more-resources.html">More Types</a></li>
            </ul>
          </li><!-- end of resource types -->
        </ul>
      </li><!-- end of app resources -->
      <li class="toggle-list">
        <div><a href="../../guide/topics/data/data-storage.html">
            <span class="en">Data Storage</span>
          </a></div>
          <ul>
            <li><a href="../../guide/topics/data/backup.html">
                <span class="en">Data Backup</span>
              </a>
            </li>
          </ul>
      </li>
      <li><a href="../../guide/topics/security/security.html">
            <span class="en">Security and Permissions</span>
          </a></li>
      <li class="toggle-list">
        <div><a href="../../guide/topics/manifest/manifest-intro.html">
          <span class="en">The AndroidManifest.xml File</span>
        </a></div>
        <ul>
          <li><a href="../../guide/topics/manifest/action-element.html">&lt;action&gt;</a></li>
          <li><a href="../../guide/topics/manifest/activity-element.html">&lt;activity&gt;</a></li>
          <li><a href="../../guide/topics/manifest/activity-alias-element.html">&lt;activity-alias&gt;</a></li>
          <li><a href="../../guide/topics/manifest/application-element.html">&lt;application&gt;</a></li>
          <li><a href="../../guide/topics/manifest/category-element.html">&lt;category&gt;</a></li>
          <li><a href="../../guide/topics/manifest/compatible-screens-element.html">&lt;compatible-screens&gt;</a></li>
          <li><a href="../../guide/topics/manifest/data-element.html">&lt;data&gt;</a></li>
          <li><a href="../../guide/topics/manifest/grant-uri-permission-element.html">&lt;grant-uri-permission&gt;</a></li>
          <li><a href="../../guide/topics/manifest/instrumentation-element.html">&lt;instrumentation&gt;</a></li>
          <li><a href="../../guide/topics/manifest/intent-filter-element.html">&lt;intent-filter&gt;</a></li>
          <li><a href="../../guide/topics/manifest/manifest-element.html">&lt;manifest&gt;</a></li>
          <li><a href="../../guide/topics/manifest/meta-data-element.html">&lt;meta-data&gt;</a></li>
          <li><a href="../../guide/topics/manifest/path-permission-element.html">&lt;path-permission&gt;</a></li>
          <li><a href="../../guide/topics/manifest/permission-element.html">&lt;permission&gt;</a></li>
          <li><a href="../../guide/topics/manifest/permission-group-element.html">&lt;permission-group&gt;</a></li>
          <li><a href="../../guide/topics/manifest/permission-tree-element.html">&lt;permission-tree&gt;</a></li>
          <li><a href="../../guide/topics/manifest/provider-element.html">&lt;provider&gt;</a></li>
          <li><a href="../../guide/topics/manifest/receiver-element.html">&lt;receiver&gt;</a></li>
          <li><a href="../../guide/topics/manifest/service-element.html">&lt;service&gt;</a></li>
          <li><a href="../../guide/topics/manifest/supports-gl-texture-element.html">&lt;supports-gl-texture&gt;</a></li>
          <li><a href="../../guide/topics/manifest/supports-screens-element.html">&lt;supports-screens&gt;</a></li><!-- ##api level 4## -->
          <li><a href="../../guide/topics/manifest/uses-configuration-element.html">&lt;uses-configuration&gt;</a></li>
          <li><a href="../../guide/topics/manifest/uses-feature-element.html">&lt;uses-feature&gt;</a></li> <!-- ##api level 4## -->
          <li><a href="../../guide/topics/manifest/uses-library-element.html">&lt;uses-library&gt;</a></li>
          <li><a href="../../guide/topics/manifest/uses-permission-element.html">&lt;uses-permission&gt;</a></li>
          <li><a href="../../guide/topics/manifest/uses-sdk-element.html">&lt;uses-sdk&gt;</a></li>
        </ul>
      </li><!-- end of the manifest file -->
    </ul>

    <ul>
    <li class="toggle-list">
        <div><a href="../../guide/topics/graphics/index.html">
            <span class="en">Graphics</span>
          </a><span class="new-child">new!</span></div>
        <ul>
          <li><a href="../../guide/topics/graphics/2d-graphics.html">
              <span class="en">Canvas and Drawables</span></a></li>
          <li><a href="../../guide/topics/graphics/hardware-accel.html">
              <span class="en">Hardware Acceleration</span></a>
            <span class="new">new!</span></li>
          <li><a href="../../guide/topics/graphics/opengl.html">
              <span class="en">OpenGL</span>
            </a><span class="new">updated</span></li>
        </ul>
      </li>
      <li class="toggle-list">
        <div><a href="../../guide/topics/graphics/animation.html">
            <span class="en">Animation</span>
          </a></div>
        <ul>
          <li><a href="../../guide/topics/graphics/prop-animation.html">
              <span class="en">Property Animation</span></a></li>
          <li><a href="../../guide/topics/graphics/view-animation.html">
              <span class="en">View Animation</span></a></li>
          <li><a href="../../guide/topics/graphics/drawable-animation.html">
              <span class="en">Drawable Animation</span></a></li>
        </ul>
      </li>
      <li class="toggle-list">
	        <div><a href="../../guide/topics/renderscript/index.html">
	            <span class="en">RenderScript</span>
	          </a></div>
	        <ul>
	          <li><a href="../../guide/topics/renderscript/graphics.html">
	                <span class="en">Graphics</span>
	              </a>
	          </li>
	          <li><a href="../../guide/topics/renderscript/compute.html">
	                <span class="en">Compute</span>
	              </a>
	          </li>
	        </ul>
  	  </li>

      <li class="toggle-list">
          <div><a href="../../guide/topics/media/index.html">
            <span class="en">Multimedia and Camera</span>
          </a><span class="new">updated</span></div>
          <ul>
            <li><a href="../../guide/topics/media/mediaplayer.html">
                  <span class="en">Media Playback</span></a>
                </li>
            <li><a href="../../guide/topics/media/jetplayer.html">
                  <span class="en">JetPlayer</span></a>
                </li>
            <li><a href="../../guide/topics/media/camera.html">
                  <span class="en">Camera</span></a>
                  <span class="new">new!</span>
                </li>
            <li><a href="../../guide/topics/media/audio-capture.html">
                  <span class="en">Audio Capture</span></a>
                </li>
          </ul>
      </li>
      <li>
        <a href="../../guide/topics/clipboard/copy-paste.html">
            <span class="en">Copy and Paste</span>
        </a></li>
  <!--<li class="toggle-list">
        <div><a style="color:gray;">Sensors</a></div>
          <ul>
            <li><a style="color:gray;">Camera</a></li>
            <li><a style="color:gray;">Compass</a></li>
            <li><a style="color:gray;">Accelerometer</a></li>
          </ul>
      </li> -->
      <li class="toggle-list">
        <div><a href="../../guide/topics/location/index.html">
               <span class="en">Location and Maps</span>
             </a></div>
        <ul>
          <li><a href="../../guide/topics/location/obtaining-user-location.html">
                <span class="en">Obtaining User Location</span>
              </a></li>
        </ul>
      </li>
  <!--<li class="toggle-list">
        <div><a style="color:gray;">Wireless Controls</a></div>
          <ul>
            <li><a style="color:gray;">Wi-Fi</a></li>
          </ul>
      </li> -->
  <!--<li><a style="color:gray;">Localization</a></li>  -->
      <li><a href="../../guide/topics/appwidgets/index.html">
            <span class="en">App Widgets</span></a>
          </li>
      <li><a href="../../guide/topics/wireless/bluetooth.html">
            <span class="en">Bluetooth</span></a>
          </li>
      <li><a href="../../guide/topics/nfc/index.html">
            <span class="en">Near Field Communication</span>
          </a></li>
      <li class="toggle-list">
          <div><a href="../../guide/topics/usb/index.html">
            <span class="en">USB</span></a>
          </div>
            <ul>
              <li><a href="../../guide/topics/usb/accessory.html">Accessory</a></li>
              <li><a href="../../guide/topics/usb/host.html">Host</a></li>
              <li><a href="../../guide/topics/usb/adk.html">Open Accessory Dev Kit</a></li>
            </ul>
          </li>

       <li><a href="../../guide/topics/network/sip.html">
            <span class="en">Session Initiation Protocol</span>
          </a></li>
      <li class="toggle-list">
        <div><a href="../../guide/topics/search/index.html">
            <span class="en">Search</span>
          </a></div>
          <ul>
            <li><a href="../../guide/topics/search/search-dialog.html">Creating a Search Interface</a></li>
            <li><a href="../../guide/topics/search/adding-recent-query-suggestions.html">Adding Recent Query Suggestions</a></li>
            <li><a href="../../guide/topics/search/adding-custom-suggestions.html">Adding Custom Suggestions</a></li>
            <li><a href="../../guide/topics/search/searchable-config.html">Searchable Configuration</a></li>
          </ul>
      </li>
      <li><a href="../../guide/topics/admin/device-admin.html">
            <span class="en">Device Administration</span></a>
      </li>
      <li class="toggle-list">
           <div>
                <a href="../../guide/topics/testing/index.html">
                   <span class="en">Testing</span>
               </a>
           </div>
           <ul>
              <li>
                <a href="../../guide/topics/testing/testing_android.html">
                <span class="en">Testing Fundamentals</span></a>
              </li>
              <li>
                <a href="../../guide/topics/testing/activity_testing.html">
                <span class="en">Activity Testing</span></a>
              </li>
              <li>
                <a href="../../guide/topics/testing/contentprovider_testing.html">
                <span class="en">Content Provider Testing</span></a>
              </li>
              <li>
                <a href="../../guide/topics/testing/service_testing.html">
                <span class="en">Service Testing</span></a>
              </li>
              <li>
                <a href="../../guide/topics/testing/what_to_test.html">
                <span class="en">What To Test</span></a>
              </li>
           </ul>
      </li>
    </ul>
  </li>

  <li>
    <h2>
      <span class="en">Android Market Topics</span>
    </h2>
    <ul>
      <li><a href="../../guide/publishing/licensing.html">
          <span class="en">Application Licensing</span></a>
      </li>
      <li class="toggle-list">
        <div><a href="../../guide/market/billing/index.html">
            <span class="en">In-app Billing</span></a>
        </div>
        <ul>
          <li><a href="../../guide/market/billing/billing_overview.html">
              <span class="en">In-app Billing Overview</span></a>
          </li>
          <li><a href="../../guide/market/billing/billing_integrate.html">
              <span class="en">Implementing In-app Billing</span></a>
          </li>
          <li><a href="../../guide/market/billing/billing_best_practices.html">
              <span class="en">Security and Design</span></a>
          </li>
          <li><a href="../../guide/market/billing/billing_testing.html">
              <span class="en">Testing In-app Billing</span></a>
          </li>
          <li><a href="../../guide/market/billing/billing_admin.html">
              <span class="en">Administering In-app Billing</span></a>
          </li>
          <li><a href="../../guide/market/billing/billing_reference.html">
              <span class="en">In-app Billing Reference</span></a>
          </li>
        </ul>
      </li>
      <li><a href="../../guide/appendix/market-filters.html">
          <span class="en">Market Filters</span></a>
      </li>
      <li><a href="../../guide/market/publishing/multiple-apks.html">
          <span class="en">Multiple APK Support</span></a>
      </li>
    </ul>
  </li>


  <li>
    <h2><span class="en">Developing</span>
               <span class="de" style="display:none">Entwicklung</span>
               <span class="es" style="display:none">Desarrollo</span>
               <span class="fr" style="display:none">Développement</span>
               <span class="it" style="display:none">Sviluppo</span>
               <span class="ja" style="display:none">開発</span>
               <span class="zh-CN" style="display:none">开发</span>
               <span class="zh-TW" style="display:none">開發</span>
    </h2>
    <ul>
  <!--<li><a href="">Developing for Android</a></li>
      signing, upgrading, selecting a package name, select device profile, touch, trackball, dpad available, etc. -->
      <li>
        <a href="../../guide/developing/index.html">
        <span class="en">Introduction</span></a>
      </li>

      <li class="toggle-list">
        <div>
           <a href="../../guide/developing/devices/index.html">
                <span class="en">Managing Virtual Devices</span>
            </a>
        </div>
        <ul>
          <li>
            <a href="../../guide/developing/devices/managing-avds.html">
              <span class="en">With AVD Manager</span>
            </a>
          </li>
          <li>
            <a href="../../guide/developing/devices/managing-avds-cmdline.html">
              <span class="en">From the Command Line</span>
            </a>
          </li>
          <li>
           <a href="../../guide/developing/devices/emulator.html">
                <span class="en">Using the Android Emulator</span>
            </a>
          </li>
        </ul>
      </li>
      <li>
        <a href="../../guide/developing/device.html">
          <span class="en">Using Hardware Devices</span>
        </a>
      </li>

      <li class="toggle-list">
        <div>
          <a href="../../guide/developing/projects/index.html">
            <span class="en">Managing Projects</span>
          </a>
        </div>
        <ul>
          <li>
            <a href="../../guide/developing/projects/projects-eclipse.html">
              <span class="en">From Eclipse with ADT</span>
            </a>
          </li>
          <li>
            <a href="../../guide/developing/projects/projects-cmdline.html">
                <span class="en">From the Command Line</span>
            </a>
          </li>
        </ul>
      </li>

      <li class="toggle-list">
        <div>
          <a href="../../guide/developing/building/index.html">
            <span class="en">Building and Running</span>
          </a>
        </div>
        <ul>
          <li><a href="../../guide/developing/building/building-eclipse.html">
            <span class="en">From Eclipse with ADT</span>
          </a></li>
          <li><a href="../../guide/developing/building/building-cmdline.html">
            <span class="en">From the Command Line</span></a></li>
        </ul>
      </li>

      <li class="toggle-list">
        <div>
          <a href="../../guide/developing/debugging/index.html">
            <span class="en">Debugging</span>
          </a>
        </div>
        <ul>
          <li>
            <a href="../../guide/developing/debugging/debugging-projects.html">
                <span class="en">From Eclipse with ADT</span>
            </a>
          </li>
          <li>
            <a href="../../guide/developing/debugging/debugging-projects-cmdline.html">
                <span class="en">From Other IDEs</span>
            </a>
          </li>
          <li>
            <a href="../../guide/developing/debugging/ddms.html">
              <span class="en">Using DDMS</span>
            </a>
          </li>
          <li>
            <a href="../../guide/developing/debugging/debugging-log.html">
                <span class="en">Reading and Writing Logs</span>
            </a>
          </li>
          <li>
            <a href="../../guide/developing/debugging/debugging-ui.html">
                <span class="en">Debugging and Profiling UIs</span>
            </a>
          </li>
          <li>
            <a href="../../guide/developing/debugging/debugging-tracing.html">
                <span class="en">Profiling with Traceview and dmtracedump</span>
            </a>
          </li>
          <li>
            <a href="../../guide/developing/debugging/debugging-devtools.html">
                <span class="en">Using the Dev Tools App</span>
            </a>
          </li>
        </ul>
      </li>

      <li class="toggle-list">
           <div>
                <a href="../../guide/developing/testing/index.html">
                   <span class="en">Testing</span>
               </a>
           </div>
           <ul>
              <li>
                <a href="../../guide/developing/testing/testing_eclipse.html">
                  <span class="en">From Eclipse with ADT</span>
                </a>
              </li>

              <li>
                <a href="../../guide/developing/testing/testing_otheride.html">
                  <span class="en">From Other IDEs</span>
                </a>
              </li>
           </ul>
         </li>

         <li class="toggle-list">
        <div><a href="../../guide/developing/tools/index.html">
            <span class="en">Tools</span>
          </a></div>
        <ul>
          <li><a href="../../guide/developing/tools/adb.html">adb</a></li>
          <li><a href="../../guide/developing/tools/adt.html">ADT</a></li>
          <li><a href="../../guide/developing/tools/android.html">android</a></li>
          <li><a href="../../guide/developing/tools/bmgr.html">bmgr</a>
          <li><a href="../../guide/developing/tools/dmtracedump.html">dmtracedump</a></li>
          <li><a href="../../guide/developing/tools/draw9patch.html">Draw
          9-Patch</a></li>
          <li><a href="../../guide/developing/tools/emulator.html">Emulator</a></li>
          <li><a href="../../guide/developing/tools/etc1tool.html">etc1tool</a></li>
          <li><a href="../../guide/developing/tools/hierarchy-viewer.html">Hierarchy Viewer</a></li>
          <li><a href="../../guide/developing/tools/hprof-conv.html">hprof-conv</a></li>
          <li><a href="../../guide/developing/tools/layoutopt.html">layoutopt</a></li>
          <li><a href="../../guide/developing/tools/logcat.html">logcat</a></li>
          <li><a href="../../guide/developing/tools/mksdcard.html">mksdcard</a></li>
          <li><a href="../../guide/developing/tools/monkey.html">Monkey</a></li>
          <li class="toggle-list">
            <div><a href="../../guide/developing/tools/monkeyrunner_concepts.html">
              <span class="en">monkeyrunner</span>
            </a></div>
            <ul>
              <li><a href="../../guide/developing/tools/MonkeyDevice.html">
                <span class="en">MonkeyDevice</span>
                </a></li>
              <li><a href="../../guide/developing/tools/MonkeyImage.html">
                <span class="en">MonkeyImage</span>
                </a></li>
              <li><a href="../../guide/developing/tools/MonkeyRunner.html">
                <span class="en">MonkeyRunner</span>
                </a></li>
            </ul>
          </li>
          <li><a href="../../guide/developing/tools/proguard.html">ProGuard</a></li>
          <li><a href="../../guide/developing/tools/adb.html#sqlite">sqlite3</a></li>
          <li><a href="../../guide/developing/tools/traceview.html">Traceview</a></li>
          <li><a href="../../guide/developing/tools/zipalign.html">zipalign</a></li>
        </ul>
      </li>
    </ul>
  </li>

  <li>
    <h2><span class="en">Publishing</span>
        <span class="de" style="display:none">Veröffentlichung</span>
        <span class="es" style="display:none">Publicación</span>
        <span class="fr" style="display:none">Publication</span>
        <span class="it" style="display:none">Pubblicazione</span>
        <span class="ja" style="display:none">公開</span>
        <span class="zh-CN" style="display:none">发布</span>
        <span class="zh-TW" style="display:none">發佈</span>
    </h2>
    <ul>
      <li><a href="../../guide/publishing/app-signing.html">
            <span class="en">Signing Your Applications</span>
            <span class="de" style="display:none">Signieren Ihrer Anwendungen</span>
            <span class="es" style="display:none">Firma de aplicaciones</span>
            <span class="fr" style="display:none">Attribution de votre signature <br />à vos applications</span>
            <span class="it" style="display:none">Firma delle applicazioni</span>
            <span class="ja" style="display:none">アプリケーションへの署名</span>
            <span class="zh-CN" style="display:none">应用程序签名</span>
            <span class="zh-TW" style="display:none">簽署應用程式</span>
          </a></li>
      <li><a href="../../guide/publishing/versioning.html">
            <span class="en">Versioning Your Applications</span>
            <span class="de" style="display:none">Versionsverwaltung für Ihre <br />Anwendungen</span>
            <span class="es" style="display:none">Versiones de las aplicaciones</span>
            <span class="fr" style="display:none">Attribution d'une version à vos applications</span>
            <span class="it" style="display:none">Controllo versioni delle applicazioni</span>
            <span class="ja" style="display:none">アプリケーションのバージョニング</span>
            <span class="zh-CN" style="display:none">应用程序版本控制</span>
            <span class="zh-TW" style="display:none">應用程式版本設定</span>
          </a></li>
      <li><a href="../../guide/publishing/preparing.html">
            <span class="en">Preparing to Publish</span>
            <span class="de" style="display:none">Vorbereitung auf die Veröffentlichung</span>
            <span class="es" style="display:none">Publicación de aplicaciones</span>
            <span class="fr" style="display:none">Préparation à la publication</span>
            <span class="it" style="display:none">Preparativi per la pubblicazione</span>
            <span class="ja" style="display:none">公開の準備</span>
            <span class="zh-CN" style="display:none">准备发布</span>
            <span class="zh-TW" style="display:none">準備發佈</span>
          </a></li>
      <li><a href="../../guide/publishing/publishing.html">
            <span class="en">Publishing on Android Market</span>
          </a></li>
    </ul>
  </li>

  <li>
    <h2><span class="en">Best Practices</span>
               <span class="de" style="display:none">Bewährte Verfahren</span>
               <span class="es" style="display:none">Prácticas recomendadas</span>
               <span class="fr" style="display:none">Meilleures pratiques</span>
               <span class="it" style="display:none">Best practice</span>
               <span class="ja" style="display:none">ベスト プラクティス</span>
               <span class="zh-CN" style="display:none">最佳实践</span>
               <span class="zh-TW" style="display:none">最佳實務</span>
    </h2>
    <ul>
      <li><a href="../../guide/practices/compatibility.html">
            <span class="en">Compatibility</span>
          </a></li>
      <li class="toggle-list">
        <div><a href="../../guide/practices/screens_support.html">
          <span class="en">Supporting Multiple Screens</span>
        </a></div>
        <ul>
          <li><a href="../../guide/practices/screens-distribution.html">
            <span class="en">Distributing to Specific Screens</span>
          </a></li>
          <li><a href="../../guide/practices/screen-compat-mode.html">
            <span class="en">Screen Compatibility Mode</span>
          </a></li>
          <li><a href="../../guide/practices/screens-support-1.5.html">
            <span class="en">Strategies for Android 1.5</span>
          </a></li>
        </ul>
      </li>
      <li><a href="../../guide/practices/optimizing-for-3.0.html">
            <span class="en">Optimizing Apps for Android 3.0</span>
          </a></li>
      <li class="toggle-list">
        <div><a href="../../guide/practices/ui_guidelines/index.html">
               <span class="en">UI Guidelines</span>
             </a></div>
        <ul>
          <li class="toggle-list">
            <div><a href="../../guide/practices/ui_guidelines/icon_design.html">
                   <span class="en">Icon Design <span class="new">updated</span></span>
                 </a></div>
            <ul>
              <li><a href="../../guide/practices/ui_guidelines/icon_design_launcher.html">
                    <span class="en">Launcher Icons <span class="new">updated</span></span>
                  </a></li>
              <li><a href="../../guide/practices/ui_guidelines/icon_design_menu.html">
                    <span class="en">Menu Icons</span>
                  </a></li>
              <li><a href="../../guide/practices/ui_guidelines/icon_design_action_bar.html">
                    <span class="en">Action Bar Icons <span class="new">new!</span></span>
                  </a></li>
              <li><a href="../../guide/practices/ui_guidelines/icon_design_status_bar.html">
                    <span class="en">Status Bar Icons <span class="new">updated</span></span>
                  </a></li>
              <li><a href="../../guide/practices/ui_guidelines/icon_design_tab.html">
                    <span class="en">Tab Icons</span>
                  </a></li>
              <li><a href="../../guide/practices/ui_guidelines/icon_design_dialog.html">
                    <span class="en">Dialog Icons</span>
                  </a></li>
              <li><a href="../../guide/practices/ui_guidelines/icon_design_list.html">
                    <span class="en">List View Icons</span>
                  </a></li>
            </ul>
          </li>
          <li><a href="../../guide/practices/ui_guidelines/widget_design.html">
                <span class="en">App Widget Design <span class="new">updated</span></span>
              </a></li>
          <li><a href="../../guide/practices/ui_guidelines/activity_task_design.html">
                <span class="en">Activity and Task Design</span>
              </a></li>
          <li><a href="../../guide/practices/ui_guidelines/menu_design.html">
                <span class="en">Menu Design</span>
              </a></li>
        </ul>
      </li>
      </ul>
      <ul>
      <li><a href="../../guide/practices/design/accessibility.html">
            <span class="en">Designing for Accessibility</span>
          </a></li>
      <li class="toggle-list">
        <div><a href="../../guide/practices/design/performance.html">
            <span class="en">Designing for Performance</span>
          </a></div>
        <ul>
          <li><a href="../../guide/practices/design/jni.html">
                <span class="en">JNI Tips</span>
              </a></li>
        </ul>
      </li>
      <li><a href="../../guide/practices/design/responsiveness.html">
            <span class="en">Designing for Responsiveness</span>
          </a></li>
      <li><a href="../../guide/practices/design/seamlessness.html">
            <span class="en">Designing for Seamlessness</span>
          </a></li>
    </ul>
  </li>

  <li>
    <h2><span class="en">Web Applications</span>
    </h2>
    <ul>
      <li><a href="../../guide/webapps/index.html">
            <span class="en">Web Apps Overview</span>
          </a></li>
      <li><a href="../../guide/webapps/targeting.html">
            <span class="en">Targeting Screens from Web Apps</span>
          </a></li>
      <li><a href="../../guide/webapps/webview.html">
            <span class="en">Building Web Apps in WebView</span>
          </a></li>
      <li><a href="../../guide/webapps/debugging.html">
            <span class="en">Debugging Web Apps</span>
          </a></li>
      <li><a href="../../guide/webapps/best-practices.html">
            <span class="en">Best Practices for Web Apps</span>
          </a></li>
    </ul>
  </li>

  <li>
    <h2><span class="en">Appendix</span>
               <span class="de" style="display:none">Anhang</span>
               <span class="es" style="display:none">Apéndice</span>
               <span class="fr" style="display:none">Annexes</span>
               <span class="it" style="display:none">Appendice</span>
               <span class="ja" style="display:none">付録</span>
               <span class="zh-CN" style="display:none">附录</span>
               <span class="zh-TW" style="display:none">附錄</span>
    </h2>
    <ul>
      <li><a href="../../guide/appendix/api-levels.html">
            <span class="en">Android API Levels</span>
          </a></li>
      <li><a href="../../guide/appendix/install-location.html">
            <span class="en">App Install Location</span>
          </a></li>
      <li><a href="../../guide/appendix/media-formats.html">
            <span class="en">Supported Media Formats <span class="new">updated</span></span>
          </a></li>
      <li><a href="../../guide/appendix/g-app-intents.html">
            <span class="en">Intents List: Google Apps</span>
          </a></li>
      <li><a href="../../guide/developing/tools/aidl.html">AIDL</a></li>
      <li><a href="../../guide/appendix/glossary.html">
            <span class="en">Glossary</span>
          </a></li>
    </ul>
  </li>

</ul>

<script type="text/javascript">
<!--
    buildToggleLists();
    changeNavLang(getLangPref());
//-->
</script>

      </div>
    </div> <!-- end side-nav -->
    <script>
      addLoadEvent(function() {
        scrollIntoView("devdoc-nav");
        });
    </script>




<div class="g-unit" id="doc-content"><a name="top"></a>

<div id="jd-header" class="guide-header">
  <span class="crumb">
    &nbsp;
    
  </span>
<h1>Application Fundamentals 基本原理</h1>
</div>

  <div id="jd-content">

    <div class="jd-descr">
    <div id="qv-wrapper">
<div id="qv">

<h2>Quickview</h2>
<ul>
  <li>Android applications are composed of one or more application components (activities,
services, content providers, and broadcast receivers)</li>
  <li>Each component performs a different role in the overall application behavior, and each
one can be activated individually (even by other applications)</li>
  <li>The manifest file must declare all components in the application and should also declare
all application requirements, such as the minimum version of Android required and any hardware
configurations required</li>
  <li>Non-code application resources (images, strings, layout files, etc.) should include
alternatives for different device configurations (such as different strings for different
languages and different layouts for different screen sizes)</li>
</ul>


<h2>In this document</h2>
<ol>
<li><a href="#Components">Application Components</a>
  <ol>
    <li><a href="#ActivatingComponents">Activating components</a></li>
  </ol>
</li>
<li><a href="#Manifest">The Manifest File</a>
  <ol>
    <li><a href="#DeclaringComponents">Declaring components</a></li>
    <li><a href="#DeclaringRequirements">Declaring application requirements</a></li>
  </ol>
</li>
<li><a href="#Resources">Application Resources</a></li>
</ol>
</div>
</div>

<p>Android applications are written in the Java programming language. The Android SDK tools compile
the code&mdash;along with any data and resource files&mdash;into an <i>Android package</i>, an
archive file with an <code>.apk</code> suffix. All the code in a single <code>.apk</code> file is considered
to be one application and is the file that Android-powered devices use to install the
application.</p>
<p>Android应用程序使用Java作为开发语言。 Android SDK工具把数据和资源文件一起编译到一个Android包里面，这个文件以.apk作为扩展名，每一个单一的.apk文件被认为是一个应用程序，Android设备可以使用这个文件安装这个应用。</p>

<p>Once installed on a device, each Android application lives in its own security sandbox: </p>
<p>一旦安装到设备中，每个Android应用程序都生活在自己的安全世界中: </p>

<ul>
 <li>The Android operating system is a multi-user Linux system in which each application is a
different user.</li>
<li>Android操作系统是一个多用户Linux系统，每个程序就是一个用户。</li>

<li>By default, the system assigns each application a unique Linux user ID (the ID is used only by
the system and is unknown to the application). The system sets permissions for all the files in an
application so that only the user ID assigned to that application can access them. </li>
<li>默认情况下，系统分配给每个应用程序一个独一无二的Linux用户ID（这个ID仅仅被用于这个系统，并且对于程序来说是未知的）。并且为程序的所有文件设置权限，让只有被分配了用户ID的程序才能访问。</li>

<li>Each process has its own virtual machine (VM), so an application's code runs in isolation from
other applications.</li>
<li>每个进程都有自己的虚拟机，所以每个程序的代码的运行是孤立的。</li>

<li>By default, every application runs in its own Linux process. Android starts the process when any
of the application's components need to be executed, then shuts down the process when it's no longer
needed or when the system must recover memory for other applications.</li>
<li>默认情况下，每个应用程序运行在自己的Linux进程中。当应用程序的任何一部分开始执行，Android就开始运行这个进程，当这个程序不需用使用或者系统其他程序需用内存资源的时候就关闭这个进程。</li>
</ul>

<p>In this way, the Android system implements the <em>principle of least privilege</em>. That is,
each application, by default, has access only to the components that it requires to do its work and
no more. This creates a very secure environment in which an application cannot access parts of
the system for which it is not given permission.</p>
<p>使用这种方式，Android系统实现最小权限原则。默认情况下，每个应用程序组件只做它自己的工作。为了建立一个安全的环境，程序不能访问系统其他没有被授权的部分。</p>

<p>However, there are ways for an application to share data with other applications and for an
application to access system services:</p>
<p>但是，应用程序直接共享数据，应用程序访问系统服务有下面这些方法：</p>

<ul>
  <li>It's possible to arrange for two applications to share the same Linux user ID, in which case
they are able to access each other's files.  To conserve system resources, applications with the
same user ID can also arrange to run in the same Linux process and share the same VM (the
applications must also be signed with the same certificate).</li>
<li>安排两个应用程序共享相同的Linux用户ID是可能的，在这种情况下，他们可以访问彼此的文件。为了节省系统资源，相同用户的程序可以安排运行在相同的Linux进程中，并且共享相同的虚拟机（程序必要有相同的签名证书）。</li>
  <li>An application can request permission to access device data such as the user's
contacts, SMS messages, the mountable storage (SD card), camera, Bluetooth, and more. All
application permissions must be granted by the user at install time.</li>
<li>一个应用程序可以请求允许访问设备数据，比如用户的通讯录，短信，可安装的存储（SD卡），照相机，蓝牙等，所有的程序许可必须在安装的时候被授予。</li>
</ul>

<p>That covers the basics regarding how an Android application exists within the system. The rest of
this document introduces you to:</p>
<p>系统内部包含了基本关于Android应用程序存在的信息。下面是文档介绍:</p>
<ul>
  <li>The core framework components that define your application.</li>
  <li>核心框架组件定义了你的应用程序</li>
  <li>The manifest file in which you declare components and required device features for your
application.</li>
<li>清单文件定义了程序必须的组件和设备特征。</li>
  <li>Resources that are separate from the application code and allow your application to
gracefully optimize its behavior for a variety of device configurations.</li>
<li>资源文件从代码中分离了出来，让程序可以在不同的配置中有合理的优化效果。</li>
</ul>

<!--
<p class="note"><strong>Tip:</strong> If you're new to Android development, we suggest that you
follow the Beginner's Path link at the bottom of this page. For each document in the Application
Fundamentals, the Beginner's Path points you to the document we suggest you read next, in order
to get up to speed on the core Android concepts.</p>
-->


<h2 id="Components">Application Components 应用程序组件</h2>

<p>Application components are the essential building blocks of an Android application. Each
component is a different point through which the system can enter your application. Not all
components are actual entry points for the user and some depend on each other, but each one exists
as its own entity and plays a specific role&mdash;each one is a unique building block that
helps define your application's overall behavior.</p>
<p>应用程序组件是Android应用程序的基本构建模块。每个组件都是系统能进入你的应用程序的不同点。不是所有的组件都是用户的真实进入点，他们相互依赖。 但是每个都是真实的存在，并且执行特别的任务，每个独一无二的构建模块都定义了程序的完整形态。</p>

<p>There are four different types of application components. Each type serves a distinct purpose
and has a distinct lifecycle that defines how the component is created and destroyed.</p>
<p>这是4个不同类型的程序组件。每个类型有不同的用途，并且有不同的生命周期。定义了组件怎么被创建和销毁的。</p>

<p>Here are the four types of application components:</p>
<p>下面是4种类型的组件：</p>

<dl>

<dt><b>Activities</b></dt>

<dd>An <i>activity</i> represents a single screen with a user interface. For example,
an email application might have one activity that shows a list of new
emails, another activity to compose an email, and another activity for reading emails. Although
the activities work together to form a cohesive user experience in the email application, each one
is independent of the others. As such, a different application can start any one of these
activities (if the email application allows it). For example, a camera application can start the
activity in the email application that composes new mail, in order for the user to share a picture.

<p>activity是为用户界面展示一个单独的界面。比如，一个邮件程序可以有一个展示新邮件列表的activity，一个写邮件的activity，一个读邮件activity。尽管这些activities在一个邮件程序中组成了一个有粘合力的用户体验，但是它们不相互依赖。同样的，一个不同的应用程序可以启动任何一个activity（如果程序允许的话）。例如，一个照相程序可以启动邮件程序中的写新邮件的activity，方便用户分享他的照片。</p>
<p>An activity is implemented as a subclass of <code><a href="../../reference/android/app/Activity.html">Activity</a></code> and you can learn more
about it in the <a href="../../guide/topics/fundamentals/activities.html">Activities</a>
developer guide.</p>
<p>你可以在开发者指南中学习更多关于一个activity是怎么执行。</p>
</dd>


<dt><b>Services</b></dt>

<dd>A <i>service</i> is a component that runs in the background to perform long-running
operations or to perform work for remote processes. A service
does not provide a user interface. For example, a service might play music in the background while
the user is in a different application, or it might fetch data over the network without
blocking user interaction with an activity. Another component, such as an activity, can start the
service and let it run or bind to it in order to interact with it.

<p>service是为了执行长期操作或者执行远程进程而运行在后台的组件。它不提供用户界面。比如，当用户在使用其他应用程序，或者使用一个activity在不堵塞的网络中下载数据，一个service可以在后台播放音乐。一个activity能够启动一个service，并且绑定它。</p>
<p>A service is implemented as a subclass of <code><a href="../../reference/android/app/Service.html">Service</a></code> and you can learn more
about it in the <a href="../../guide/topics/fundamentals/services.html">Services</a> developer
guide.</p>
</dd>


<dt><b>Content providers 内容提供者</b></dt>

<dd>A <i>content provider</i> manages a shared set of application data. You can store the data in
the file system, an SQLite database, on the web, or any other persistent storage location your
application can access. Through the content provider, other applications can query or even modify
the data (if the content provider allows it). For example, the Android system provides a content
provider that manages the user's contact information. As such, any application with the proper
permissions can query part of the content provider (such as <code><a href="../../reference/android/provider/ContactsContract.Data.html">ContactsContract.Data</a></code>) to read and write information about a particular person.
<p>content provider管理程序间的数据共享。你可以保存数据在系统文件中，SQLite数据库中，网络中，或者其他你的程序能够访问的固定存储器。通过内容提供者，其他程序能查询数据，甚至是修改数据。比如，Android系统提供一个管理用户联系人信息的content provider。任何其他有合适授权的应用程序都可以通过部分content provider执行读写联系人信息的操作。</p>

<p>Content providers are also useful for reading and writing data that is private to your
application and not shared. For example, the <a
href="../../resources/samples/NotePad/index.html">Note Pad</a> sample application uses a
content provider to save notes.</p>
<p>Content providers对于读写私有数据也是很有用的，例如，记事本的例子就使用了content provider保存事件。</p>

<p>A content provider is implemented as a subclass of <code><a href="../../reference/android/content/ContentProvider.html">ContentProvider</a></code>
and must implement a standard set of APIs that enable other applications to perform
transactions. For more information, see the <a
href="../../guide/topics/providers/content-providers.html">Content Providers</a> developer
guide.</p>
</dd>


<dt><b>Broadcast receivers 广播接收器</b></dt>

<dd>A <i>broadcast receiver</i> is a component that responds to system-wide broadcast
announcements.  Many broadcasts originate from the system&mdash;for example, a broadcast announcing
that the screen has turned off, the battery is low, or a picture was captured.
Applications can also initiate broadcasts&mdash;for example, to let other applications know that
some data has been downloaded to the device and is available for them to use. Although broadcast
receivers don't display a user interface, they may <a
href="../../guide/topics/ui/notifiers/notifications.html">create a status bar notification</a>
to alert the user when a broadcast event occurs. More commonly, though, a broadcast receiver is
just a "gateway" to other components and is intended to do a very minimal amount of work. For
instance, it might initiate a service to perform some work based on the event.
<p>广播接收器用来响应整个系统的广播公告。系统会有很多广播发出。比如，屏幕关闭广播，电量不足，或者拍摄一张照片。应用程序也可以开始一个广播，比如，让其他程序知道数据已经下载到设备中，并且可用了。虽然广播接收器不提供一个用户界面，但是当一个广播事件产生的时候会弹出一个状态栏通知用户。简单的说，广播接收器就各个组件间的通道，只要很小的工作量就可以完成广播通知。例如，你可以基于这个通知去启动一个服务去完成一些工作。</p>
<p>A broadcast receiver is implemented as a subclass of <code><a href="../../reference/android/content/BroadcastReceiver.html">BroadcastReceiver</a></code>
and each broadcast is delivered as an <code><a href="../../reference/android/content/Intent.html">Intent</a></code> object. For more information,
see the <code><a href="../../reference/android/content/BroadcastReceiver.html">BroadcastReceiver</a></code> class.</p>
</dd>

</dl>



<p>A unique aspect of the Android system design is that any application can start another
application’s component. For example, if you want the user to capture a
photo with the device camera, there's probably another application that does that and your
application can use it, instead of developing an activity to capture a photo yourself. You don't
need to incorporate or even link to the code from the camera application.
Instead, you can simply start the activity in the camera application that captures a
photo. When complete, the photo is even returned to your application so you can use it. To the user,
it seems as if the camera is actually a part of your application.</p>
<p>Android系统独特的一点是任何程序可以启动其他程序的组件。比如，你用照相程序启动摄像头拍摄一张照片，其他程序也可以使用这张照片，而不需要开发一个activity去拍摄照片。你也不需要合并或者关联代码到照相程序。取而代之的是，你仅仅需要开始照相程序的activity，然后拍照，照片就可以返回给你的程序使用了。在用户看来，照相程序就像是你的应用程序的一部分。</p>

<p>When the system starts a component, it starts the process for that application (if it's not
already running) and instantiates the classes needed for the component. For example, if your
application starts the activity in the camera application that captures a photo, that activity
runs in the process that belongs to the camera application, not in your application's process.
Therefore, unlike applications on most other systems, Android applications don't have a single entry
point (there's no <code>main()</code> function, for example).</p>
<p>当系统启动一个组件，那么它需要为应用程序启动这个组件的进程，并且实例化这个组件需要的类。例如，如果你要启动一个照相程序的activity来拍摄照片，这个activity运行在照相程序的进程中，不是在你的程序进程中。所以，和其他系统的程序不一样，Android应用程序不仅仅有一个程序入口（前面翻译的进入点应该是程序入口）。</p>

<p>Because the system runs each application in a separate process with file permissions that
restrict access to other applications, your application cannot directly activate a component from
another application. The Android system, however, can. So, to activate a component in
another application, you must deliver a message to the system that specifies your <em>intent</em> to
start a particular component. The system then activates the component for you.</p>
<p>因为每个应用程序都运行在单独的使用授权文件的进程中，这些程序被限制访问其他程序，所以你的应用程序不能直接激活其他应用程序的组件。在Android系统中，为了启动特定的组件，你必须发送一条指明了intent的消息给系统，系统就会激活这个组件给你。</p>

<h3 id="ActivatingComponents">Activating Components 激活组件</h3>

<p>Three of the four component types&mdash;activities, services, and
broadcast receivers&mdash;are activated by an asynchronous message called an <em>intent</em>.
Intents bind individual components to each other at runtime (you can think of them
as the messengers that request an action from other components), whether the component belongs
to your application or another.</p>
<p>activitier,services,broadcast receivers都需要一个叫intent的异步消息去激活。Intents在运行的时候会绑定特定的组件，不管组件是属于哪个应用程序。</p>

<p>An intent is created with an <code><a href="../../reference/android/content/Intent.html">Intent</a></code> object, which defines a message to
activate either a specific component or a specific <em>type</em> of component&mdash;an intent
can be either explicit or implicit, respectively.</p>
<p>通过一个intent对象可以创建一个intent，这个intent定义了一个消息去启动一个特定的组件或者一个特定类型的组件。一个intent可以是显示的，或者暗示的，独立的地</p>

<p>For activities and services, an intent defines the action to perform (for example, to "view" or
"send" something) and may specify the URI of the data to act on (among other things that the
component being started might need to know). For example, an intent might convey a request for an
activity to show an image or to open a web page. In some cases, you can start an
activity to receive a result, in which case, the activity also returns
the result in an <code><a href="../../reference/android/content/Intent.html">Intent</a></code> (for example, you can issue an intent to let
the user pick a personal contact and have it returned to you&mdash;the return intent includes a
URI pointing to the chosen contact).</p>
<p>对于activities和services来说，intent定义了一个任务并去执行，并且指定数据的统一标示符。例如，一个intent可能为一个activity传达一个显示图片或者打开网页的请求。同时，你能开始一个activity去接收一个结果，这个activity也返回一个结果给一个intent。</p>

<p>For broadcast receivers, the intent simply defines the
announcement being broadcast (for example, a broadcast to indicate the device battery is low
includes only a known action string that indicates "battery is low").</p>
<p>对于broadcast receivers来说，intent简单定义了广播通知的存在。比如，一个指明设备电量不足的广播仅仅包括一个‘电量不足’的字符串。</p>

<p>The other component type, content provider, is not activated by intents. Rather, it is
activated when targeted by a request from a <code><a href="../../reference/android/content/ContentResolver.html">ContentResolver</a></code>. The content
resolver handles all direct transactions with the content provider so that the component that's
performing transactions with the provider doesn't need to and instead calls methods on the <code><a href="../../reference/android/content/ContentResolver.html">ContentResolver</a></code> object. This leaves a layer of abstraction between the content
provider and the component requesting information (for security).</p>
<p>对于内容提供者，不需要通过intent启动。当ContentResolver有目标请求的时候它会启动。内容解析器处理内容提供者的所有事务，所以对于提供者来说，执行事务的组件不是必须的，取代它的是调用ContentResolver对象中的方法。这就留下了一个内容提供者和组件请求信息之间的一个抽象层（为了安全考虑）</p>

<p>There are separate methods for activiting each type of component:</p>
<p>下面是激活不同类型组件的方法：</p>
<ul>
  <li>You can start an activity (or give it something new to do) by
passing an <code><a href="../../reference/android/content/Intent.html">Intent</a></code> to <code><a href="../../reference/android/content/Context.html#startActivity(android.content.Intent)">startActivity()</a></code> or <code><a href="../../reference/android/app/Activity.html#startActivityForResult(android.content.Intent, int)">startActivityForResult()</a></code>
(when you want the activity to return a result).</li>
  <li>You can start a service (or give new instructions to an ongoing service) by
passing an <code><a href="../../reference/android/content/Intent.html">Intent</a></code> to <code><a href="../../reference/android/content/Context.html#startService(android.content.Intent)">startService()</a></code>. Or you can bind to the service by passing an <code><a href="../../reference/android/content/Intent.html">Intent</a></code> to
<code><a href="../../reference/android/content/Context.html#bindService(android.content.Intent, android.content.ServiceConnection, int)">bindService()</a></code>.</li>
  <li>You can initiate a broadcast by passing an <code><a href="../../reference/android/content/Intent.html">Intent</a></code> to methods like
<code><a href="../../reference/android/content/Context.html#sendBroadcast(android.content.Intent)">sendBroadcast()</a></code>, <code><a href="../../reference/android/content/Context.html#sendOrderedBroadcast(android.content.Intent, java.lang.String)">sendOrderedBroadcast()</a></code>, or <code><a href="../../reference/android/content/Context.html#sendStickyBroadcast(android.content.Intent)">sendStickyBroadcast()</a></code>.</li>
  <li>You can perform a query to a content provider by calling <code><a href="../../reference/android/content/ContentProvider.html#query(android.net.Uri, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String)">query()</a></code> on a <code><a href="../../reference/android/content/ContentResolver.html">ContentResolver</a></code>.</li>
</ul>

<p>For more information about using intents, see the <a
href="../../guide/topics/intents/intents-filters.html">Intents and
Intent Filters</a> document. More information about activating specific components is also provided
in the following documents: <a
href="../../guide/topics/fundamentals/activities.html">Activities</a>, <a
href="../../guide/topics/fundamentals/services.html">Services</a>, <code><a href="../../reference/android/content/BroadcastReceiver.html">BroadcastReceiver</a></code> and <a
href="../../guide/topics/providers/content-providers.html">Content Providers</a>.</p>


<h2 id="Manifest">The Manifest File 清单文件</h2>

<p>Before the Android system can start an application component, the system must know that the
component exists by reading the application's <code>AndroidManifest.xml</code> file (the "manifest"
file). Your application must declare all its components in this file, which must be at the root of
the application project directory.</p>
<p>当Android系统启动一个应用程序组件之前，它必须知道这个组件是存在的，这个组件被声明在AndroidManifest.xml中。你的应用程序必须在这个文件中定义所有的组件，并且放在应用程序工程的主目录下。</p>

<p>The manifest does a number of things in addition to declaring the application's components,
such as:</p>
<p>manifest除了定义了应用程序的组件，还包括下面这些信息：</p>
<ul>
  <li>Identify any user permissions the application requires, such as Internet access or
read-access to the user's contacts.</li>
  <li>定义应用程序需要的用户权限，比如网络访问或者读取用户通讯录。</li>
  <li>Declare the minimum <a href="../../guide/appendix/api-levels.html">API Level</a>
required by the application, based on which APIs the application uses.</li>
<li>定义了应用程序需要使用的最基本的API</li>
  <li>Declare hardware and software features used or required by the application, such as a camera,
bluetooth services, or a multitouch screen.</li>
<li>定义了应用程序需要的软件和硬件装置，比如摄像头，蓝牙，多点触控屏。</li>
  <li>API libraries the application needs to be linked against (other than the Android framework
APIs), such as the <a
href="http://code.google.com/android/add-ons/google-apis/maps-overview.html">Google Maps
library</a>.</li>
<li>其他应用程序必须连接到的API库</li>
  <li>And more</li>
</ul>


<h3 id="DeclaringComponents">Declaring components 组件说明</h3>

<p>The primary task of the manifest is to inform the system about the application's components. For
example, a manifest file can declare an activity as follows: </p>
<p>manifest的主要任务是告知系统这个应用程序的组件。比如，一个manifest这样定义一个activity：</p>
<pre>
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest ... &gt;
    &lt;application android:icon="@drawable/app_icon.png" ... &gt;
        &lt;activity android:name="com.example.project.ExampleActivity"
                  android:label="@string/example_label" ... &gt;
        &lt;/activity&gt;
        ...
    &lt;/application&gt;
&lt;/manifest&gt;</pre>

<p>In the <code><a
href="../../guide/topics/manifest/application-element.html">&lt;application&gt;</a></code>
element, the <code>android:icon</code> attribute points to resources for an icon that identifies the
application.</p>
<p>&lt;application&gt;元素中，android:icon属性指定了一个icon资源去标识这个application</p>

<p>In the <code><a
href="../../guide/topics/manifest/activity-element.html">&lt;activity&gt;</a></code> element,
the <code>android:name</code> attribute specifies the fully qualified class name of the <code><a href="../../reference/android/app/Activity.html">Activity</a></code> subclass and the <code>android:label</code> attributes specifies a string
to use as the user-visible label for the activity.</p>
<p>&lt;activity&gt;元素中，android:name属性指定了一个完全标准的Activity子类的类名，android:label属性指定这个activity显示给用户标签的字符串。</p>

<p>You must declare all application components this way:</p>
<p>你可以定义所有的组件用下面这些方法：</p>
<ul>
  <li><code><a
href="../../guide/topics/manifest/activity-element.html">&lt;activity&gt;</a></code> elements
for activities</li>
  <li><code><a
href="../../guide/topics/manifest/service-element.html">&lt;service&gt;</a></code> elements for
services</li>
  <li><code><a
href="../../guide/topics/manifest/receiver-element.html">&lt;receiver&gt;</a></code> elements
for broadcast receivers</li>
  <li><code><a
href="../../guide/topics/manifest/provider-element.html">&lt;provider&gt;</a></code> elements
for content providers</li>
</ul>

<p>Activities, services, and content providers that you include in your source but do not declare
in the manifest are not visible to the system and, consequently, can never run.  However,
broadcast
receivers can be either declared in the manifest or created dynamically in code (as
<code><a href="../../reference/android/content/BroadcastReceiver.html">BroadcastReceiver</a></code> objects) and registered with the system by calling
<code><a href="../../reference/android/content/Context.html#registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter)">registerReceiver()</a></code>.</p>
<p>对于Activities, services, and content providers来说，如果你在代码中包含他们，但是没有在manifest文件中定义，那么他们是不会运行的。然而，broadcast receiver能够在未定义的情况下在代码中动态创建，并且通过registerReceiver()方法注册。</p>

<p>For more about how to structure the manifest file for your application, see the <a
href="../../guide/topics/manifest/manifest-intro.html">The AndroidManifest.xml File</a>
documentation. </p>



<h3 id="DeclaringComponentCapabilities">Declaring component capabilities 定义组件能力</h3>

<p>As discussed above, in <a href="#ActivatingComponents">Activating Components</a>, you can use an
<code><a href="../../reference/android/content/Intent.html">Intent</a></code> to start activities, services, and broadcast receivers. You can do so
by explicitly naming the target component (using the component class name) in the intent. However,
the real power of intents lies in the concept of intent actions. With intent actions, you simply
describe the type of action you want to perform (and optionally, the data upon which you’d like to
perform the action) and allow the system to find a component on the device that can perform the
action and start it. If there are multiple components that can perform the action described by the
intent, then the user selects which one to use.</p>
<p>像上面Activating Components说的，你可以使用intent启动activities, services, and broadcast receivers.你可以在intent中明确的命名组件的名称。然而，真正的有用的是intent action，你可以简单的描述你想运行的action的类型，然后让系统去寻找可运行的组件，并启动它。如果有很多个组件符号这个action的描述，那么由用户自己选择需要的组件。</p>

<p>The way the system identifies the components that can respond to an intent is by comparing the
intent received to the <i>intent filters</i> provided in the manifest file of other applications on
the device.</p>
<p>系统识别组件的方法是，响应设备中应用程序的manifest提供的intent filters过滤后的intent。</p>

<p>When you declare a component in your application's manifest, you can optionally include
intent filters that declare the capabilities of the component so it can respond to intents
from other applications. You can declare an intent filter for your component by
adding an <a href="../../guide/topics/manifest/intent-filter-element.html"><code>&lt;intent-filter&gt;</code></a> element as a child of the component's declaration element.</p>
<p>当你在manifest中定义一个组件，你可以选择包含定义了组件能力的intent filters，它可以响应其他程序的intents。你也可以定义一个子的intent filter。</p>

<p>For example, an email application with an activity for composing a new email might declare an
intent filter in its manifest entry to respond to "send" intents (in order to send email). An
activity in your application can then create an intent with the “send” action (<code><a href="../../reference/android/content/Intent.html#ACTION_SEND">ACTION_SEND</a></code>), which the system matches to the email application’s “send”
activity and launches it when you invoke the intent with <code><a href="../../reference/android/app/Activity.html#startActivity(android.content.Intent)">startActivity()</a></code>.</p>
<p>例如，一个邮件程序的发邮件activity可以定义一个intent filter在manifest文件中去响应“发送”这个intent。你的应用程序中的一个activity能够通过ACTION_SEND去创建一个intent，当你通过startActivity()调用intent的时候，系统会匹配邮件程序中的“发送”activity，并运行它。</p>

<p>For more about creating intent filters, see the <a
href="../../guide/topics/intents/intents-filters.html">Intents and Intent Filters</a> document.
</p>



<h3 id="DeclaringRequirements">Declaring application requirements 定义程序需求</h3>

<p>There are a variety of devices powered by Android and not all of them provide the
same features and capabilities. In order to prevent your application from being installed on devices
that lack features needed by your application, it's important that you clearly define a profile for
the types of devices your application supports by declaring device and software requirements in your
manifest file. Most of these declarations are informational only and the system does not read
them, but external services such as Android Market do read them in order to provide filtering
for users when they search for applications from their device.</p>
<p>有各种各样的设备使用Android系统，但是不是所有的设备都提供相同的配置和性能。为了防止你的应用程序安装在配置达不到要求的设备中，在你的manifest文件中清晰的定义你的应用程序的硬件和软件需求是很重要的。大部分声明仅仅是提醒，系统并不读取它们，但是Android Market这种外部服务会读取它们，为了用户在搜索应用程序的时候能够提供一些过滤。</p>

<p>For example, if your application requires a camera and uses APIs introduced in Android 2.1 (<a
href="../../guide/appendix/api-levels.html">API Level</a> 7), you should declare these as
requirements in your manifest file. That way, devices that do <em>not</em> have a camera and have an
Android version <em>lower</em> than 2.1 cannot install your application from Android Market.</p>
<p>比如，如果你的应用程序需要一个摄像头和使用Android2.1的API，那么你需要在manifest文件中声明你的需求。这样的话，设备中没有摄像头或者版本低于2.1就不能安装你的应用程序。</p>

<p>However, you can also declare that your applicaiton uses the camera, but does not
<em>require</em> it. In that case, your application must perform a check at runtime to determine
if the device has a camera and disable any features that use the camera if one is not available.</p>
<p>当然，你可以定义你的程序需要摄像头，但是又不是必须的。这样的话，在你的程序运行的时候要提供一个选择。</p>

<p>Here are some of the important device characteristics that you should consider as you design and
develop your application:</p>
<p>下面是一些你开发和设计中需要考虑的重要设备特征：</p>

<dl>
  <dt>Screen size and density 屏幕大小和密度</dt>
  <dd>In order to categorize devices by their screen type, Android defines two characteristics for
each device: screen size (the physical dimensions of the screen) and screen density (the physical
density of the pixels on the screen, or dpi&mdash;dots per inch). To simplify all the different
types of screen configurations, the Android system generalizes them into select groups that make
them easier to target.
<p>为了给屏幕分类，Android定义了两种特征：屏幕大小（实际尺度）和屏幕密度（屏幕的像素密度或者分辨率）。从而简化所有不同的屏幕类型配置，Android系统把它们概括成简单的组别。</p>

<p>The screen sizes are: small, normal, large, and extra large.<br/>
The screen densities are: low density, medium density, high density, and extra high density.</p>
<p>尺寸是：小，中，大，超大<br/>
密度是：低密度，中等密度，高密度，超高密度</p>

<p>By default, your application is compatible with all screen sizes and densities,
because the Android system makes the appropriate adjustments to your UI layout and image
resources. However, you should create specialized layouts for certain screen sizes and provide
specialized images for certain densities, using alternative layout resources, and by declaring in
your manifest exactly which screen sizes your application supports with the <a
href="../../guide/topics/manifest/supports-screens-element.html"><code>&lt;supports-screens&gt;</code></a> element.</p>
<p>默认情况下，你的应用程序是兼容所有屏幕尺寸和密度的，因为Android系统会对你的UI布局和图像资源做相应的调整。可是，你必须为确切的屏幕尺寸创建特别的布局，为确定的分辨率提供特别的图像，并且定义在manifest文件中你的程序支持哪些屏幕尺寸。</p>

<p>For more information, see the <a
href="../../guide/practices/screens_support.html">Supporting Multiple Screens</a>
document.</p></dd>

  <dt>Input configurations 输入配置</dt>
  <dd>Many devices provide a different type of user input mechanism, such as a hardware keyboard, a
trackball, or a five-way navigation pad. If your application requires a particular kind of input
hardware, then you should declare it in your manifest with the <a
href="../../guide/topics/manifest/uses-configuration-element.html"><code>&lt;uses-configuration&gt;</code></a> element. However, it is rare that an application should require
a certain input configuration.
<p>很多设备提供不同的输入机制，像硬键盘，轨迹球，或者一个五位导航pad。如果你的应用程序需要一个特殊的输入设备，那么你必须在manifest文件中声明你的需求在uses-configuration元素中。</p></dd>

  <dt>Device features 设备特征</dt>
  <dd>There are many hardware and software features that may or may not exist on a given
Android-powered device, such as a camera, a light sensor, bluetooth, a certain
version of OpenGL, or the fidelity of the touchscreen. You should never assume that a certain
feature is available on all Android-powered devices (other than the availability of the standard
Android library), so you should declare any features used by your application with the <a
href="../../guide/topics/manifest/uses-feature-element.html"><code>&lt;uses-feature&gt;</code></a>
element.
<p>安装了Android系统的设备有很多硬件和软件特征，像摄像头，光传感器，蓝牙，一个特点版本的OpenGL，或者精确的触摸屏。你不能假定一个特定的特征在所有的Android设备中都是可用的，所有你必须为你应用程序定义一些特征，通过uses-feature</p></dd>

  <dt>Platform Version 平台版本</dt>
  <dd>Different Android-powered devices often run different versions of the Android platform,
such as Android 1.6 or Android 2.3. Each successive version often includes additional APIs not
available in the previous version. In order to indicate which set of APIs are available, each
platform version specifies an <a
href="../../guide/appendix/api-levels.html">API Level</a> (for example, Android 1.0 is API Level
1 and Android 2.3 is API Level 9). If you use any APIs that were added to the platform after
version 1.0, you should declare the minimum API Level in which those APIs were introduced using the
<a href="../../guide/topics/manifest/uses-sdk-element.html"><code>&lt;uses-sdk&gt;</code></a>
element.
<p>不同的设备会运行不同的Android版本，比如Android 1.6 或者Android2.3。后续的版本经常包含以下前期版本不能使用的API。为了指明哪个API是可用的，每个版本都规定了一个API Level。比如，Android 1.0是API Level 1，Android 2.3是API Level 9。如果你使用任何高于Android 1.0 的版本的API，那么你必须使用uses-sdk元素声明你支持的最低版本API Level。</p></dd>
</dl>

<p>It's important that you declare all such requirements for your application, because, when you
distribute your application on Android Market, Market uses these declarations to filter which
applications are available on each device. As such, your application should be available only to
devices that meet all your application requirements.</p>
<p>声明你的应用程序需求是很重要的，因为，当你在Android Market中分类你的应用程序的时候，Market使用这些声明去筛选那些设备能使用那些应用程序。同样的，你的应用程序也仅仅在符合需求的设备中可用。</p>

<p>For more information about how Android Market filters applications based on these (and other)
requirements, see the <a href="../../guide/appendix/market-filters.html">Market Filters</a>
document.</p>



<h2 id="Resources">Application Resources 资源</h2>

<p>An Android application is composed of more than just code&mdash;it requires resources that are
separate from the source code, such as images, audio files, and anything relating to the visual
presentation of the application. For example, you should define animations, menus, styles, colors,
and the layout of activity user interfaces with XML files. Using application resources makes it easy
to update various characteristics of your application without modifying code and&mdash;by providing
sets of alternative resources&mdash;enables you to optimize your application for a  variety of
device configurations (such as different languages and screen sizes).</p>
<p>Android应用程序不仅仅是由代码组成。像图片，声频，和任何可视化相关的文件都会被从源代码中分离出来。比如，你必须在xml文件中定义动画，菜单，样式，颜色，和用户界面活动布局。在不需要修改代码的情况下，你可以使用这些资源文件简单的生成各式各样的应用系统，在不同的设备中配置中可以提供不同的资源选择。</p>

<p>For every resource that you include in your Android project, the SDK build tools define a unique
integer ID, which you can use to reference the resource from your application code or from
other resources defined in XML. For example, if your application contains an image file named <code>logo.png</code> (saved in the <code>res/drawable/</code> directory), the SDK tools generate a resource ID
named <code>R.drawable.logo</code>, which you can use to reference the image and insert it in your
user interface.</p>
<p>在你的Android项目中，每个资源都会被SDK工具生成一个整数ID，你可以在你的应用程序或者其他资源中引用这些资源。比如，如果你的程序中包含一个logo.png图片，SDK工具给这个图片生成了一个资源ID为R.drawble.logo的名称。那么你可以在界面中引用并插入这张图片。</p>

<p>One of the most important aspects of providing resources separate from your source code
is the ability for you to provide alternative resources for different device
configurations. For example, by defining UI strings in XML, you can translate the strings into other
languages and save those strings in separate files. Then, based on a language <em>qualifier</em>
that you append to the resource directory's name (such as <code>res/values-fr/</code> for French string
values) and the user's language setting, the Android system applies the appropriate language strings
to your UI.</p>
<p>提供代码和资源文件的分离最重要的原因就是为不同设备配置提供不同的资源选择。例如，在定义界面字符串的xml中，你可以翻译这些字符，然后保存到单独的文件中，然后放在合适语言文件夹中，通过用户语言的设定，Android系统会在你的界面中适用合适的语言文件。</p>

<p>Android supports many different <em>qualifiers</em> for your alternative resources. The
qualifier is a short string that you include in the name of your resource directories in order to
define the device configuration for which those resources should be used. As another
example, you should often create different layouts for your activities, depending on the
device's screen orientation and size. For example, when the device screen is in portrait
orientation (tall), you might want a layout with buttons to be vertical, but when the screen is in
landscape orientation (wide), the buttons should be aligned horizontally. To change the layout
depending on the orientation, you can define two different layouts and apply the appropriate
qualifier to each layout's directory name. Then, the system automatically applies the appropriate
layout depending on the current device orientation.</p>
<p>Android为你的可选择的资源提供了很多不同的限定符。限定符以短字符串的形式命名在你的资源目录中，以便定义设备配置知道那个资源被使用。再比如，因为设备屏幕方向和尺寸不同，你可能会为你的activities定义不同的布局，当设备屏幕的竖向的时候，你可能为按钮设计了垂直的布局，但是当屏幕是横向的时候，按钮必须是水平排列的。布局的改变依赖于方向，你可以定义两个不同布局，然后为每个布局目录名限定不同的名称，系统会根据当前屏幕访问调用合适的布局。</p>

<p>For more about the different kinds of resources you can include in your application and how
to create alternative resources for various device configurations, see the <a
href="../../guide/topics/resources/index.html">Application Resources</a> developer guide.</p>


<!--
<h2>Beginner's Path</h2>

<p>For a close look at implementing activities&mdash;the components your users use to
interact with your application&mdash;continue with the <b><a
href="../../guide/topics/fundamentals/activities.html">Activities</a></b> document.</p>
-->

    </div>

  <a href="#top" style="float:right">&uarr; Go to top</a>
  
  </div>

<div id="footer">


  <div id="copyright">
    
  Except as noted, this content is licensed under <a
  href="http://www.apache.org/licenses/LICENSE-2.0">Apache 2.0</a>. 
  For details and restrictions, see the <a href="../../license.html">
  Content License</a>.
  </div>
  <div id="build_info">
    
  Android 4.0&nbsp;r1 - 17 Oct 2011 18:17

  </div>

  <div id="footerlinks">
    
  <p>
    <a href="http://www.android.com/terms.html">Site Terms of Service</a> -
    <a href="http://www.android.com/privacy.html">Privacy Policy</a> -
    <a href="http://www.android.com/branding.html">Brand Guidelines</a>
  </p>
  </div>

</div> <!-- end footer -->

</div><!-- end doc-content -->

</div> <!-- end body-content --> 

<script type="text/javascript">
init(); /* initialize android-developer-docs.js */
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-5831155-1");
pageTracker._trackPageview();
</script>

</body>
</html>



